home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / mplus_1.exe / MENUDEMO.C < prev    next >
C/C++ Source or Header  |  1991-12-01  |  17KB  |  611 lines

  1. /*--------------------------------------------------------------
  2.  *  File:           MENUDEMO.C
  3.  *  Description:    Demo the MPLUS Menu System. 
  4.  *
  5.  *  This demo developed for the MPLUS Graphic Interface Library.
  6.  *-------------------------------------------------------------*/
  7.  
  8. #include <stdio.h>
  9. #include <graph.h>
  10. #include <math.h>
  11.  
  12. #include "gplus.h"
  13. #include "gscreen.h"
  14. #include "mouser.h"
  15. #include "mpmenu.h"
  16.  
  17. #define ESC     0x011B          /* scan & ascii code for ESC key */
  18. #define CTRL_M   0x320D         /* hot key for memory */
  19.  
  20. int dummy(), exitfun();
  21. int memfun();
  22. int mres(), hres(), eres(), vres();
  23. int info(), demo1(), demo2();
  24.  
  25. void sinplot();
  26. void setaxis();
  27.  
  28. /*--------------------------------------------------------------
  29.  *  Initialize menu structures.
  30.  *-------------------------------------------------------------*/
  31.  
  32. /*      Titles for pull down menus.  Main menu bar done last because
  33.  *      of backward referencing.
  34.  */
  35.  
  36. struct MENU_ITEM mi_file[] =
  37. {
  38.     "Save", dummy, NULL, 0, 0,1,0,      /* dummy entries marked */
  39.     "Load", dummy, NULL, 0, 0,1,0,      /*   with grey out */
  40.     "DOS",  dummy, NULL, 0, 0,1,0,
  41.     "Exit to System", exitfun, NULL, 0, 0,0,0,
  42.     NULL, NULL, NULL, 0,0,0,
  43. };
  44.  
  45. struct MENU_ITEM mi_system[] =
  46. {
  47.     "Memory\tCTRL+M", memfun, NULL, CTRL_M, 0,0,0,
  48.     NULL, NULL, NULL, 0, 0,0,0,
  49. };
  50.  
  51. struct MENU_ITEM mi_videomode[] = 
  52. {
  53.     "Medium Res 4 Color", mres, NULL, 0, 0,0,0,
  54.     "Hi Res Black & White", hres, NULL, 0, 0,0,0,
  55.     "EGA", eres, NULL, 0, 0,0,0,
  56.     "VGA", vres, NULL, 0, 0,0,0,
  57.     NULL, NULL, NULL, 0, 0,0,0,
  58. };
  59.  
  60. struct MENU_ITEM mi_help[] = 
  61. {
  62.     "Info", info, NULL, 0, 0,0,0,
  63.     "Demo 1", demo1, NULL, 0, 0,0,0,
  64.     "Demo 2", demo2, NULL, 0, 0,0,0,
  65.     NULL, NULL, NULL, 0, 0,0,0,
  66. };
  67.  
  68. /*      Titles for main menu goes last because of backward
  69.  *      referencing of pulldown menu structures.
  70.  */
  71. struct MENU_ITEM menubar[] =
  72. {
  73.     "File", NULL, mi_file, 0, 1, 0, 0,    
  74.     "System", NULL, mi_system, 0, 1, 0, 0, 
  75.     "Video", NULL, mi_videomode, 0, 1, 0, 0,
  76.     "Help", NULL, mi_help, 0, 1, 0, 0,
  77.     "Exit", exitfun, NULL, 0, 0, 0, 0,
  78.     NULL, NULL, NULL, 0,0,0,
  79. };
  80.     
  81. struct MENU_INFO menu_info = 
  82. {
  83.     ESC, exitfun,                           /* exit key & function */
  84.     BLACK, CYAN, RED, GREY,                 /* attr of bar menu */
  85.     _GBORDER, BLUE, WHITE, BLUE, GREY,      /* attr of pull down windows */
  86. };
  87.  
  88. extern struct videoconfig _videoconfig;
  89.  
  90. /*--------------------------------------------------------------
  91.  *  Function:       main
  92.  *  Description:    demos the bar menu.
  93.  *  Return value:   0 returned to parent process.
  94.  *--------------------------------------------------------------*/
  95. main()
  96. {
  97.     int ret;
  98.     int (*funptr)();
  99.     char ms_flag;
  100.  
  101.     /*      Try to set video mode to EGA
  102.      */
  103.     if( mpsetvideomode( _ERESCOLOR ) )
  104.         mi_videomode[2].checkmark = 1;      /* check off EGA mode in menu */
  105.     else if( mpsetvideomode( _HRESBW ) )
  106.         mi_videomode[1].checkmark = 1;      /* check of HRES in menu */
  107.     else
  108.     {
  109.         printf("\nUnrecognized video hardware.\n");
  110.         exit(1);
  111.     }
  112.  
  113.     /*      Open menu bar with colors defined in menu_info.
  114.      */
  115.     mb_open( 1, 1, 80, &menu_info, menubar );
  116.  
  117.     ms_flag = ms_reset();
  118.     ms_setevent(1);
  119.     ms_showcursor();
  120.  
  121.     if( ms_flag == 0 )
  122.     {
  123.         gdialog( GDINFORM, GDOKAY );
  124.         gdwrite( "No mouse detected but keyboard is\n" );
  125.         gdwrite( "supported.  Press \"O\" to quit dialogue\n");
  126.         gdwrite( "box, then press ALT+first letter of\n");
  127.         gdwrite( "menu title.  See chapter 6.\n");
  128.         gdprompt();
  129.         gdclose();
  130.     }
  131.  
  132.     funptr = NULL;
  133.  
  134.     while( funptr != exitfun || ret != 0)
  135.     {
  136.         funptr = mb_run();
  137.         if ( funptr != NULL)
  138.             ret = funptr();             /* execute selected function */
  139.     }
  140.     mb_close();
  141.     ms_setevent(0);
  142.     mpsetvideomode( _DEFAULTMODE );
  143.     return 0;
  144. }
  145. /*--------------------------------------------------------------
  146.  *  Function:       dummy
  147.  *  Description:    Dummy function to invoke from bar menu
  148.  *  Return value:   0
  149.  *--------------------------------------------------------------*/
  150. int dummy()
  151. {
  152.     gdialog( GDINFORM, GDOKAY );
  153.     gdwrite("Function not available.");
  154.     gdprompt();
  155.     gdclose();
  156.     return 0;
  157. }
  158. /*--------------------------------------------------------------
  159.  *  Function:       exitfun
  160.  *  Description:    quit this program
  161.  *  Return value:   0
  162.  *--------------------------------------------------------------*/
  163. int exitfun()
  164. {
  165.     int i;
  166.  
  167.     gdialog( GDWARN, GDYESNO );
  168.     gdwrite( "Quit bar menu demo?");
  169.     i = gdprompt();
  170.     gdclose();
  171.  
  172.     return i;
  173. }
  174. /*--------------------------------------------------------------
  175.  *  Function:       memfun
  176.  *  Description:    Display memory info to dialog box
  177.  *  Return value:   0
  178.  *--------------------------------------------------------------*/
  179. int memfun()
  180. {
  181.     char buffer[41];
  182.  
  183.     gdialog( GDINFORM, GDOKAY );
  184.  
  185.     sprintf( buffer, "Memory available: %u bytes\n", _memavl() );
  186.     gdwrite( buffer );
  187.     sprintf( buffer, "Max contiguous block: %u bytes\n", _memmax() );
  188.     gdwrite( buffer );
  189.  
  190.     gdprompt();
  191.     gdclose();
  192.  
  193.     return 0;
  194. }
  195. /*--------------------------------------------------------------
  196.  *  Function:       mres
  197.  *  Description:    Set the screen to medium resolution, 4 color
  198.  *  Return value:   0
  199.  *--------------------------------------------------------------*/
  200. int mres()
  201. {
  202.     char buffer[41];
  203.     int i;
  204.  
  205.     gdialog( GDINFORM, GDOKCAN );
  206.     gdwrite( "Reset mode to four color,\nmedium resolution?" );
  207.     i = gdprompt();
  208.     gdclose();
  209.  
  210.     if( i == 0 )
  211.     {
  212.         mb_close();
  213.         if( mpsetvideomode( _MRES4COLOR ) == 0 )
  214.         {
  215.             gdialog( GDERROR, GDOKAY );
  216.             gdwrite( "Video mode not supported by hardware." );
  217.             gdprompt();
  218.             gdclose();
  219.         }
  220.         else
  221.         {
  222.             /*      Select colors for palette 1
  223.              */
  224.             _selectpalette(1);
  225.  
  226.             menu_info.fg0 = 0x01;       /* cyan */
  227.             menu_info.bg0 = 0x02;       /* magenta */
  228.             menu_info.keycolor0 = 0x03; /* light grey */
  229.  
  230.             menu_info.fg = 0x01;        /* cyan */
  231.             menu_info.bg = 0x03;        /* light grey */
  232.             menu_info.keycolor = 0x01;
  233.  
  234.             menu_info.greyout0 = menu_info.greyout = 0x03;
  235.  
  236.             /*  all checkmarks off.  Check off first title in menu.
  237.              */
  238.             mb_setbits( mi_videomode, MB_CHECKMARK, 0 ); 
  239.             mi_videomode[0].checkmark = 1;
  240.  
  241.             mb_open( 1, 1, 80, &menu_info, menubar );
  242.             ms_showcursor();
  243.         }
  244.     }
  245.     
  246.     return 0;
  247. }
  248. /*--------------------------------------------------------------
  249.  *  Function:       hres
  250.  *  Description:    Set the screen to black and white hi res
  251.  *  Return value:   0
  252.  *--------------------------------------------------------------*/
  253. int hres()
  254. {
  255.     char buffer[41];
  256.     int i;
  257.  
  258.     gdialog( GDINFORM, GDOKCAN );
  259.     gdwrite( "Reset mode to black and white,\nhigh resolution?" );
  260.     i = gdprompt();
  261.     gdclose();
  262.  
  263.     if( i == 0 )
  264.     {
  265.         mb_close();
  266.         if( mpsetvideomode( _HRESBW ) == 0 )
  267.         {
  268.             gdialog( GDERROR, GDOKAY );
  269.             gdwrite( "Video mode not supported by hardware." );
  270.             gdprompt();
  271.             gdclose();
  272.         }
  273.         else
  274.         {
  275.             /*      Reset colors to black and white.
  276.              */
  277.             menu_info.fg0 = menu_info.fg = 0x00;
  278.             menu_info.bg0 = menu_info.bg = 0x07;
  279.             menu_info.keycolor0 = menu_info.keycolor = 0x07;
  280.             menu_info.greyout0 = menu_info.greyout = 0x07;
  281.  
  282.             /*  all checkmarks off.  Check off second title in menu.
  283.              */
  284.             mb_setbits( mi_videomode, MB_CHECKMARK, 0 ); 
  285.             mi_videomode[1].checkmark = 1;
  286.  
  287.             mb_open (1,1,80,